package heima.lm.oschina.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import heima.lm.oschina.BaseApplication;
import heima.lm.oschina.R;
import heima.lm.oschina.adapter.FriendCircleAdapter;
import heima.lm.oschina.base.BaseActivity;
import heima.lm.oschina.bean.Active;
import heima.lm.oschina.bean.ActiveList;
import heima.lm.oschina.common.CommonPager;
import heima.lm.oschina.constant.Constants;
import heima.lm.oschina.utils.HttpUtils;
import heima.lm.oschina.utils.UIUtils;

/**
 * Created by Administrator on 2017/4/5.
 */

public class FriendCircleActivity extends BaseActivity {


    private CommonPager mCommonPager;
    private List<Active> mList;

    @BindView(R.id.toolbar_fc)
    Toolbar mToolbar;

    @BindView(R.id.rv_friend_circle)
    RecyclerView mRecyclerView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mCommonPager = new CommonPager() {
            @Override
            protected void loadData() {
                FriendCircleActivity.this.loadData();
            }

            @Override
            protected void loadSuccessPager() {
                FriendCircleActivity.this.loadSuccessPager();
            }
        };
        setContentView(mCommonPager.mRootView);
        BaseApplication.mActivityList.add(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mCommonPager.dynamic();
    }

    private void loadSuccessPager() {
        View successView = View.inflate(UIUtils.getContext(), R.layout.activity_friend_circle, null);
        ButterKnife.bind(this, successView);
        mToolbar.setNavigationIcon(R.drawable.actionbar_back_icon_normal);
        mToolbar.setTitle("好友圈");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FriendCircleActivity.this.finish();
            }
        });
        LinearLayoutManager layoutManager = new LinearLayoutManager(UIUtils.getContext());
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(new FriendCircleAdapter(mList));
        mCommonPager.changeView(successView);
    }

    private void loadData() {
        HttpUtils<ActiveList> httpUtils = new HttpUtils<>();
        Map<String, String> params = new HashMap<>();
        params.put("page", "0");
        httpUtils.getData(Constants.Http.ACTIVE_LIST1, params, ActiveList.class, new HttpUtils.OnHttpResponseListener<ActiveList>() {
            @Override
            public void onSuccess(ActiveList bean) {
                mList = bean.getActivelist();
                mCommonPager.dealCommonSuccess(mList);
            }

            @Override
            public void onFailure(Exception e) {
                mCommonPager.dealCommonFailure();
            }
        });
    }

}
